package com.ytjj.qmyx.users.controller;


import com.ytjj.common.service.RedisService;
import com.ytjj.qmyx.users.dao.UsersDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 脚本
 */
@Slf4j
@RestController
@RequestMapping("/scrip")
public class ScriptControll {

    @Resource
    private UsersDao usersDao;
    @Resource
    private RedisService redisService;


    /**
     * 清除有问题的token(修复微信openId不对的问题)
     * @return
     */
    @GetMapping("/cleanToken")
    public String cleanToken(){
        try {
            List<String> list =  usersDao.findToken();
            for (String key:list){
                try {
                    redisService.remove(key);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "fail";
        }
        return "success";
    }

}
